{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "18d41f34-6219-4e8f-abd4-a5543315fe86",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "打开浏览器访问页面2023-05-09 18:58\n",
      "浏览器启动并访问登录页成功，请速速扫码\n"
     ]
    }
   ],
   "source": [
    "from selenium.webdriver.chrome.options import Options\n",
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "from selenium.webdriver.chrome.service import Service\n",
    "import time\n",
    "import sys\n",
    "import json\n",
    "import qzone\n",
    "\n",
    "# 设置浏览器\n",
    "options = Options()\n",
    "# options.add_argument('blink-settings=imagesEnabled=false')\n",
    "options.add_argument('--window-size=800,400') # 大小\n",
    "options.add_argument('--no-sandbox')\n",
    "options.add_argument('--headless')  # 无头参数浏览器不提供可视化页面\n",
    "options.add_argument('--disable-gpu')\n",
    "options.add_argument('--disable-software-rasterizer')\n",
    "options.add_argument('--disable-extensions')\n",
    "options.add_argument('--ignore-certificate-errors')\n",
    "options.add_argument('--allow-running-insecure-content')\n",
    "\n",
    "# 开始\n",
    "# print(\"打开浏览器访问页面\" + time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time())))\n",
    "driver = webdriver.Chrome(service=Service(r\"./chromedriver\"), options=options)\n",
    "attr = {} # 获取参数\n",
    "with open('./data.json', 'r', encoding='utf8') as fp: attr = json.load(fp)\n",
    "qzone.getCode(driver)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "393cf84e-08a0-45ed-9b7a-aed49c4695bb",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始访问页面...  2023-05-09 18:58\n",
      "https://user.qzone.qq.com/3505457127/311\n",
      "访问出错跳过\n",
      "https://user.qzone.qq.com/2747799504/311\n",
      "访问出错跳过\n",
      "https://user.qzone.qq.com/2907195009/311\n",
      "应该是没登录，截张图，返回False\n",
      "没登录\n",
      "页面访问完毕，lis生成，解析发送...\n",
      "浏览器必须退出\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'bool' object is not iterable",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[3], line 6\u001b[0m\n\u001b[1;32m      4\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;129;01mnot\u001b[39;00m lis): \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m没登录\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m      5\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m页面访问完毕，lis生成，解析发送...\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 6\u001b[0m     qzone\u001b[38;5;241m.\u001b[39msendBlogs(\u001b[43mqzone\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhandleBlogs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlis\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m      8\u001b[0m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[1;32m      9\u001b[0m     driver\u001b[38;5;241m.\u001b[39mquit()\n",
      "File \u001b[0;32m~/jpt/qzoneWeb/qzone.py:62\u001b[0m, in \u001b[0;36mhandleBlogs\u001b[0;34m(lis)\u001b[0m\n\u001b[1;32m     59\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mhandleBlogs\u001b[39m(lis):\n\u001b[1;32m     60\u001b[0m     \u001b[38;5;66;03m# 解析\u001b[39;00m\n\u001b[1;32m     61\u001b[0m     lisoups \u001b[38;5;241m=\u001b[39m []\n\u001b[0;32m---> 62\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m li \u001b[38;5;129;01min\u001b[39;00m lis:\n\u001b[1;32m     63\u001b[0m         lisoup \u001b[38;5;241m=\u001b[39m BeautifulSoup(li[\u001b[38;5;241m0\u001b[39m],\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlxml\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m     64\u001b[0m         \u001b[38;5;66;03m# 过滤掉转发的说说\u001b[39;00m\n",
      "\u001b[0;31mTypeError\u001b[0m: 'bool' object is not iterable"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    print(\"开始访问页面...  \" + time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time())))\n",
    "    lis = qzone.getBlogs(driver,attr)\n",
    "    if (not lis): print(\"没登录\")\n",
    "    print(\"页面访问完毕，lis生成，解析发送...\")\n",
    "    qzone.sendBlogs(qzone.handleBlogs(lis))\n",
    "\n",
    "finally:\n",
    "    driver.quit()\n",
    "    print('浏览器必须退出')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "284214ca-195b-41ca-b24e-2b0384660bd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.quit()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
